package com.xique.door.controller;


import com.xique.common.core.web.controller.BaseController;
import com.xique.common.core.web.page.TableDataInfo;
import com.xique.common.security.annotation.PreAuthorize;
import com.xique.door.bean.domain.PermissionGroupDCard;
import com.xique.door.bean.request.commandV1.DeviceCommandGetRecStatusRequest;
import com.xique.door.bean.request.permissionGroup.PermissionGroupUserRequest;
import com.xique.door.biz.service.IPermissionGroupUserBizService;
import com.xique.door.biz.service.IDeviceCommandService;
import com.xique.door.service.IPermissionGroupService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Deprecated
@Controller
@RequestMapping("/oms/permissionGroupDCard")
public class PermissionGroupDCardController extends BaseController {

    private String prefix = "oms/permissionGroupDCard";

    @Autowired
    private IPermissionGroupService permissionGroupService;

    @Autowired
    private IPermissionGroupUserBizService permissionGroupUserBizService;

    @Autowired
    private IDeviceCommandService deviceCommandService;

    /**
     * 分配卡片
     */
    @PreAuthorize(hasPermi = "oms:permissionGroup:edit")
    @GetMapping("/addDCard/{id}")
    public String addUser(@PathVariable("id") Long id, ModelMap mmap) {
        mmap.put("group", permissionGroupService.selectPermissionGroupById(id));
        return prefix + "/addDCard";
    }

    /**
     * 查询已分配用户的卡片权限组列表
     * 1、查询该权限组下所有用户的卡片；
     */
    @PreAuthorize(hasPermi = "oms:permissionGroup:list")
    @PostMapping("/addDCard/allocatedDCardList/{parkId}")
    @ResponseBody
    public TableDataInfo allocatedUserList(PermissionGroupUserRequest request, ModelMap mmap) {
        startPage();
        List<PermissionGroupDCard> list = permissionGroupService.selectAllocatedDCardList(request);
        //用户同步状态
        DeviceCommandGetRecStatusRequest recStatusRequest = new DeviceCommandGetRecStatusRequest();
        recStatusRequest.setCards(list);
        recStatusRequest.setGroupId(request.getGroupId());
        recStatusRequest.setClassName("User");
        //状态赋值
        return getDataTable(deviceCommandService.getDCardRecStatus(recStatusRequest));
    }
}
